function PlotImageHistNorm(image,titletext)
% Plot the normalised histogram of a N-dim image with appropriate text in title
%
%   - Michael Eager,   (michael.eager@monash.edu) 
%   - (c) 2012, Monash Biomedical Imaging, Monash University, Australia

%     Copyright © 2012-2013 Michael Eager <michael.eager@monash.edu> 
%
%     This file is part of Xglom.
% 
%     This is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.



hMsg=msgbox(['Calculating histogram'],'Xglom Message . . . ');

nimage = NormaliseImage(image);
[h x] = hist(nimage(:),300);
delete(findobj(hMsg,'string','OK'));delete(findobj(hMsg,'style','frame'));mpos= get(hMsg,'position');set(hMsg,'position',[mpos(1)+36 mpos(2)-48 mpos(3:4)] );drawnow;

hHist=figure;
set(0,'CurrentFigure',hHist)
% subplot(2,1,1);
% imagesc(nimage)
% colormap(flipud(gray));
% axis square;
%subplot(2,1,2);
plot(x,log10(h));
title(titletext,'FontSize',22);
ylabel('Log Frequency','FontSize',16)
xlabel('Image Values (Normalised)','FontSize',16)
axis(get(hHist,'children'),'normal');

